<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>广告管理</title>
		<%@ include file="../../common/Admin-list.jsp"%>  
		<link rel="stylesheet" type="text/css" href="<%=basePath %>easyui/themes/gray/easyui.css"/>  
		<link rel="stylesheet" type="text/css" href="<%=basePath %>easyui/themes/icon.css"/>   
		<script type="text/javascript" src="<%=basePath %>JS/jquery/jquery-1.7.1.min.js"></script>     
		<script type="text/javascript" src="<%=basePath %>easyui/jquery.easyui.min.js"></script>
	
 		<script type="text/javascript">
			$(function(){
				
				$('#dataGridSys').datagrid({		
					height:'505',
					width:'100%',
					rownumbers:true,//设置为true将显示行数					
					striped:true, //设置为true将交替显示行背景
					fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
					animate:true,
					collapsible:true,
					idField:'id',//id字段
					pagination : true,//分页控件
					pageSize : 10,
				    pageList : [10, 20, 30],
				    url : '../siteAd/listData.json',
					loadMsg : '数据装载中......',
					singleSelect : true,//设置为 true，则只允许选中一行						
					columns:[[					          	
								{field:'id',hidden:true,editor:{type:'text'}},
								{field:'typeName',title:'广告类型',width:100,align:'left',editor:{type:'text'}},
								{field:'title',title:'标题',width:100,align:'left',editor:{type:'text'}},								
								{field:'link',title:'链接路径',width:100,align:'left',editor:{type:'text'}},														
								{field:'filepath',title:'缩略图',width:100,align:'left',editor:{type:'text'},
								    formatter:function(value,row,index){
									    return '<img src="'+row.filepath+'" width="120" height="25" />';
									}								
								},												
								{field:'width',title:'尺寸',width:30,align:'center',editor:{type:'text'},
									formatter:function(value,row,index){
										if(value!=null){
											 return value+'×'+row.height;
										}else{
											return "";
										}
									   
									}
								},
								{field:'height',hidden:true,title:'高度',width:40,align:'center',editor:{type:'text'}},
								{field:'sortid',title:'排序 ',width:40,align:'center',editor:{type:'text'}},
								{field:'visible',title:'是否显示',width:40,align:'center',editor:{type:'text'},
									formatter:function(value,row,index){
										if(value=='0'){
												return "√";
											}else{
												return "";
										}
									}
								},								
								{field:'opt',title:'操作',width:100,align:'left',  
				                    formatter:function(value,rec,index){
				                    	var up='<a title="上移" href="#" onclick="UpDown(\''+ rec.id + '\','+(Number(rec.sortid)-1)+')">' +
		                    					'<img src="<%=basePath %>pages/Admin/Images/Icon/up.gif" alt="Up"></a>&nbsp;&nbsp;';
		                    			
                    					var down='<a title="下移" href="javascript:UpDown(\''+ rec.id + '\','+(Number(rec.sortid)+1)+')">' +
                    							'<img src="<%=basePath %>pages/Admin/Images/Icon/down.gif" alt="Down"></a>&nbsp;&nbsp;';
                   			
				                    	
				                    	var edit='<a title="编辑" onclick="edit(\''+ rec.id + '\')"  href="#">'+
				                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;&nbsp;&nbsp;';
				                    	
				                        var dele='<a title="删除" onclick="del(\''+ rec.id +'\')"  href="#">'+
				                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';				                        
				                                                 
				                        return up+down+edit+dele;  
				                    }  
				                 }								
					        ]]	
				});	
				
				
				//广告类型
				$('#typeid').combobox({
					 url: '../SysTypeID/queryAll.json?tableName=Site_AD&is_deleted=0',
					 valueField: 'id',  //显示下拉菜单中的值
				   	 textField: 'typeName',
				   	 editable : false				   	
				});	
				
			});
			
			//排序 
			function UpDown(pkId,newSort){  								
				$.ajax({  
					type: "POST",  
			        url: '../siteAd/update.json', 
		    	    data:{  
		    	    	  id:pkId,
		    	    	  sortid:newSort,
		    	    	  type:'upDown'
		    	    },  
		    	    type:'post',  
		    	    cache:false,  
		    	    dataType:'json',  
		    	    success:function(map) {  
		    	    	if(map.success){		    	    		
		    	    		$('#dataGridSys').datagrid('reload');
		    	    	}		    	    	    	           
		    	    },  
		    	     error : function() {  
		    	          alert("异常！");  
		    	     }  
		    	});					
	           
	        }
			
			function edit(index){  //编辑   
				art.dialog.open('../siteAd/updateInterface.htm?type=edit&id='+index,{
					title: '修改广告信息',
					id:'editDialog',
					lock:true,
				  	width: '90%',
				    height: '70%'												   												   
				},function(){
					$('#dataGridSys').datagrid('reload');
				});
          	}
			
			function del(index){  //删除操作
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该数据？',
				    ok: function () {				    	
				    	$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../siteAd/delete.json',
							data:{id:index,delSub:true},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('删除成功！');
									window.location.reload();  
								}else{
									art.dialog.alert('删除失败，请联系管理员！');
								}
							}
						});
				    },
				    cancelVal: '取消',
				    cancel: true 
				});				
          	}
		
			
			function refresh()
			{
				$('#dataGridSys').datagrid('reload');
			}
			
			function addAD(){ //新增广告					
				art.dialog.open('../siteAd/addInterface.htm?type=add',{
					title: '增加广告图片',
					id:'addDialog',
					lock:true,
				  	width: '90%',
				    height: '70%'												   												   
				});				
	      	}
			
			function searchList() {
				var queryParams = $('#dataGridSys').datagrid('options').queryParams;	
				
				queryParams.typeid =$('#typeid').combobox('getValue');						
				if($('#visible').is(':checked')) {
					queryParams.visible =$('#visible').val();//是否显示
				}else{
					delete queryParams.visible;
				}
				$('#dataGridSys').datagrid('load');
				$('#dataGridSys').datagrid('clearSelections');
			}
			
			
		</script>	
	</head>
	<body>
		<div>
			<table id="dataGridSys"  style="width: 100%;"  type="dataGrid"	data-options="toolbar:'#toolBar'"></table>
			<div id="toolBar" style="height: auto;padding:0px;">
				<!--表单  搜索栏-->
				<div id="filter" class="module">					
					<ul> 					
						<li>
							<label>广告类型：</label>							
	        				<select name="typeid" id="typeid"  class="easyui-combobox" style="width:250px;">  </select>										
						</li>
						<li>
							&nbsp;&nbsp;&nbsp;&nbsp;
							 <input id="visible" type="checkbox" name="visible" checked="checked" value="0"  style="width:10px;vertical-align:middle;" />
	                	 	 <label for="visible" style="margin-right:8px;">网站显示</label>
						</li>
						
						<li>
							<input type="button" class="btn btn-blue-h20-w2" value="查询" onclick="searchList()" />
						</li>					
					</ul>
					<div class="clear"></div>
				</div>
				<!--表单  列表栏-->
				<div class="list module">
					<div class="hd">
						<h2 class="t">数据列表</h2>
						<span class="handle4filter" title="显示/隐藏查询条件"></span>
					</div>
					<div class="bd">
						<div id="toolbar">
							<ul id="buttonPlace">														
								<li>
									<a  href="javascript:addAD()" class="icon add" hideFocus="false"><span class = "glyphicon glyphicon-plus" style="display:in-line"></span>增加</a>
								</li>
								<li>
									<a href="javascript:refresh()" class="icon reload"  hideFocus="false"><span class = "glyphicon glyphicon-edit" style="display:in-line"></span>刷新</a>
								</li> 				
											
							</ul>
						</div>
					</div>
				</div>
			
			</div>
		</div>
	</body>
</html>